package com.example.home.model

import com.bawei.common.entity.CommendEntity
import com.bawei.common.entity.SimpleVideoEntity
import com.example.common.entity.SimpleTypeEntity
import com.example.common.model.BaseRepository
import com.example.home.api.HomeServerApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow


import javax.inject.Inject

class HomeRepository @Inject constructor(private val apiServer:HomeServerApi):BaseRepository<HomeServerApi>() {

    suspend fun getSimpleTypes(): Flow<List<SimpleTypeEntity>> {
        return flow {
            var result = apiServer.getSimpleTypes()
            if(result.code ==0){
                emit(result.data)
            }else{
                emit(listOf())
            }
        }
    }

    suspend fun getSimpleVideoByChannelId(channelId:String,page:Int,pageSize:Int):Flow<List<SimpleVideoEntity>>{
        return flow {
            var result = apiServer.getSimpleVideoByChannelId(channelId,page,pageSize)
            if(result.code ==0){
                emit(result.data)
            }else{
                emit(listOf())
            }
        }
    }

    suspend fun getRecommendVideo(page:Int,pageSize:Int):Flow<List<SimpleVideoEntity>>{
        return flow {
            var result = apiServer.getRecommendSimpleVideo(page,pageSize)
            if(result.code==0){
                emit(result.data)
            }else{
                emit(listOf())
            }
        }
    }

    suspend fun getSimpleVideoCommends(dataType:Int,itemId:String):Flow<List<CommendEntity>>{
        return flow {
            var result = apiServer.getVideoCommends(dataType,itemId)
            if(result.code==0){
                emit(result.data)
            }else{
                emit(listOf())
            }
        }


    }





}